package com.hhss.qishi.entity.common;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.validation.constraints.NotEmpty;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.hhss.qishi.config.annotation.ChineseName;

/**
 * 实体们的父类
 * @author hhss
 * @date 2019年3月30日 
 */
@SuppressWarnings("serial")
public class BasePojo extends PagePojo implements Serializable, Comparable<BasePojo>{
	
	@Id
	@Column(name = "id", updatable = false)
	@ChineseName("主键")
	private Long id;
	
	@Column(name = "uuid", updatable = false)
	@ChineseName("唯一标识")
	private String uuid;
	
	@Column(name = "status")
	@ChineseName("状态标识 默认1，删除后0")
	private Integer status;
	
	@Column(name = "create_user", updatable = false)
	@ChineseName("创建者")
	private String createUser;
	
	@NotEmpty
	@Column(name = "create_time", updatable = false)
	@ChineseName("创建时间")
	private Date createTime;
	
	@Column(name = "last_update_user")
	@ChineseName("修改者")
	private String lastUpdateUser;
	
	@Column(name = "last_update_time")
	@ChineseName("修改时间")
	private Date lastUpdateTime;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the uuid
	 */
	public String getUuid() {
		return uuid;
	}

	/**
	 * @param uuid the uuid to set
	 */
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	/**
	 * @return the createUser
	 */
	public String getCreateUser() {
		return createUser;
	}

	/**
	 * @param createUser the createUser to set
	 */
	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @return the lastUpdateUser
	 */
	public String getLastUpdateUser() {
		return lastUpdateUser;
	}

	/**
	 * @param lastUpdateUser the lastUpdateUser to set
	 */
	public void setLastUpdateUser(String lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	/**
	 * @return the lastUpdateTime
	 */
	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	/**
	 * @param lastUpdateTime the lastUpdateTime to set
	 */
	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	@Override
	public int compareTo(BasePojo other) {
		if(isTransient() && other.isTransient()) {
			int cmp = hashCode() - other.hashCode();
			return cmp == 0 ? 0 : cmp > 0 ? 1 : -1;
		}
		if(isTransient()) {
			return -1;
		}
		if(other.isTransient()) {
			return 1;
		}
		return id.compareTo(other.getId());
	}
	
	public boolean isTransient() {
		return id == null;
	}
}
